package com.cx.factory;

/**
 * @author zhangshuai
 * @version V1.0
 * @Project Java2_26
 * @Package com.cx.factory
 * @Description:
 * @Date 2025/5/27 9:11
 */

public interface Factory {
    /**
     * 创建对象方法
     * @return
     */
    Shape createBean();
}
//在工厂类中创建对象
class TriangleFactory implements Factory{
    @Override
    public Shape createBean() {
        return new Triangle();
    }
}
class SquareFactory implements Factory{
    @Override
    public Shape createBean() {
        return new Square();
    }
}
class OtherFactory implements Factory{
    @Override
    public Shape createBean() {
        return new Other();
    }
}
class FactoryTest{
    public static void main(String[] args) {
        /**
         * 工厂模式：
         * 1.工厂模式是一种创建型设计模式，它提供了一种创建对象的最佳方式。
         * 2.在工厂模式中，我们在创建对象时不会对客户端暴露创建逻辑，并且是通过使用一个共同的接口来指向新创建的对象。
         */
        Factory factory = new TriangleFactory();
        Shape shape = factory.createBean();
        shape.draw();
        Factory squareFactory = new SquareFactory();
        Shape shape1 = squareFactory.createBean();
        shape1.draw();
        Factory otherFactory = new OtherFactory();
        Shape shape2 = otherFactory.createBean();
        shape2.draw();

    }
}